$(function () {

    var html_data = {
        baseConfig: baseConfig,
        sessionid: '',
        sessionid_q: '',
        default_address: null,
        selected_address_id: parseInt(GetQueryString('address_id')),
        payorder_id: parseInt(GetQueryString("payorder_id")),
        address_list: []

    };
    var app = new Vue({
        el: '#user_address_html',
        data: html_data,
        methods: {
            choice_address: function (payorder_id, address_id) {
                if (payorder_id) {
                    api.lorder.update_pay_order_address({
                        order_id: payorder_id,
                        address_id: address_id
                    }).then(function (data) {
                        baseConfig.page_back();
                        // location.href = 'pay.html?payorder_id=' + payorder_id;
                        // history.go(-1);
                    });
                }

            },
            create_address: function () {
                location.href = 'address_modefy.html?payorder_id=' + html_data.payorder_id;
            },
            modefy_address: function (address_id) {
                location.href = 'address_modefy.html?payorder_id=' + html_data.payorder_id + '&address_id=' + address_id;
            },
            update_default_address: function (default_address) {
                api.lorder.update_default_address({address_id: default_address}).then(function (data) {

                })
            },
            delete_address: function (address) {
                api.lorder.delete_address({address_id: address.id}).then(function (data) {
                    address.is_active = false;
                })
            },
            page_back: function () {
                baseConfig.page_back();
            }
        }
    });

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }

    document.getElementsByTagName("BODY")[0].onpageshow = function (event) {
        if(event && !event.persisted){
            return;
        }
        api.lorder.query_address_list().then(function (data) {
            html_data.address_list = data.result.list;
            _(data.result.list).each(function (item) {
                if (item.is_default) {
                    html_data.default_address = item.id;
                }
            })
        });
    };
    document.getElementsByTagName("BODY")[0].onpageshow();




});
